package xyz.quanguanjia.masterboy.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import xyz.quanguanjia.masterboy.R;
import xyz.quanguanjia.masterboy.model.MBDMessageInfoModel;

public class MessageListAdapter extends RecyclerView.Adapter {
    private List<MBDMessageInfoModel> groupDetailList;

    public MessageListAdapter(List<MBDMessageInfoModel> gd) {
        this.groupDetailList = gd;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // 创建列表项视图
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_message, parent, false);
        return new MBDGroupDetailViewHolder(view);

    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        // 绑定数据到列表项视图
        MBDMessageInfoModel detail = this.groupDetailList.get(position);
        ((MBDGroupDetailViewHolder) holder).bind(detail);
    }

    @Override
    public int getItemCount() {
        return this.groupDetailList.size();
    }

    public static class MBDGroupDetailViewHolder extends RecyclerView.ViewHolder {
        private TextView nameTextView, contentTv;

        public MBDGroupDetailViewHolder(@NonNull View itemView) {
            super(itemView);
            nameTextView = itemView.findViewById(R.id.name_tv);
            contentTv = itemView.findViewById(R.id.content_tv);
        }

        public void bind(MBDMessageInfoModel detail) {
            // 设置列表项视图的数据
            nameTextView.setText(detail.title);
            contentTv.setText(detail.content);
        }
    }
}
